<template>
  <div class="bottom">
    <div class="now">{{ time }}</div>
    <div class="total">
      <div>一共 &nbsp;{{ getCount }}&nbsp; 件</div>
      <div class="price">合计￥{{ getTotal }}</div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { PropType, computed } from 'vue'

const props = defineProps({
  shopArr: {
    type: Array as PropType<any[]>,
    default: () => []
  },
  time: {
    type: String,
    default: null
  }
})

const getCount = computed(() => {
  const arr = props.shopArr
  let res = 0
  for (let i = 0; i < arr.length; i++) {
    res += arr[i].quantity
  }
  return res
})

const getTotal = computed(() => {
  const arr = props.shopArr
  let res = 0
  for (let i = 0; i < arr.length; i++) {
    res += arr[i].quantity * arr[i].price
  }

  const toFixedNum = Number(res).toFixed(3)
  const realVal = toFixedNum.substring(0, toFixedNum.toString().length - 1)
  return realVal
})

defineExpose({
  getTotalPrice: () => {
    return getTotal.value
  }
})
</script>

<style lang="less" scoped>
.bottom {
  border-top: 1px dashed #000;
  padding: 10px 16px;
  font-size: 14px;
  background-color: #fff;
  position: relative;

  .now {
    margin-top: 10px;
  }

  .total {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;

    .price {
      color: rgb(12, 52, 186);
      font-weight: bold;
    }
  }

  &::before {
    content: '';
    display: block;
    position: absolute;
    top: -10px;
    left: -10px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: rgb(245, 245, 245);
  }

  &::after {
    content: '';
    display: block;
    position: absolute;
    top: -10px;
    right: -10px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: rgb(245, 245, 245);
  }
}
</style>
